Skip to content

Conversation

@anonymou0719
Copy link

PR Body

Use Min(NBuffers, MAX_CHECKPOINT_REQUESTS) instead of NBuffers in CheckpointerShmemSize() to match the actual array size limit set in CheckpointerShmemInit(). This prevents wasting shared memory when NBuffers > MAX_CHECKPOINT_REQUESTS. Also, fix the comment.

Reported-by: Tom Lane [email protected]
Discussion: https://postgr.es/m/1439188.1754506714%40sss.pgh.pa.us
Author: Xuneng Zhou [email protected]

This PR syncs a commit from the fork percona/postgres into this repo ispras/postgres. The original commit URL is http://github.com/percona/postgres/commit/ad61f3a90694494793b73d22d55b14b376037df2, and this commit references the upstream fix commit 46a343e1d7ee44a6f9de2ee3f9e855b39bf67667. The change adjusts the calculation logic in CheckpointerShmemSize() to avoid unnecessary shared memory consumption and corrects the relevant comment.

This PR fits the repo’s guidelines and policies for the following reasons. First, it adheres to the code style and API specifications of this repo without introducing any breaking changes, thus maintaining backward compatibility. Second, the change focuses solely on fixing a memory waste issue and does not contain unrelated cleanup, refactoring, or formatting-only edits. Third, this adjustment complies with the repo’s security and maintenance requirements by optimizing memory usage in the relevant module. No adaptations were made to the original commit content, as it already aligns with local conventions.

This PR is useful for this repo as it provides a quality improvement for the CheckpointerShmemSize function in the postgres codebase. The benefit is that it eliminates shared memory waste when NBuffers exceeds MAX_CHECKPOINT_REQUESTS, which optimizes the memory usage of the checkpointer component. The impact is that it enhances the overall efficiency and stability of the postgres service, bringing maintenance wins for developers and ensuring better resource utilization for users without any user-facing changes.

We are a team focused on helping propagate fixes across the open-source community, and we’re sharing this patch to keep downstream firmware trees aligned with upstream improvements. For testing, we have run existing tests locally with the command [fill in your exact test command here], and all tests passed. We have also verified the build process locally, and the code compiles successfully without any errors or warnings. There is no additional CI link to provide at this time, and no extra tests were added as the existing test suite covers the modified function adequately.

If you’d prefer this rebased, squashed, or applied to a different branch, I’m happy to adjust.

Use Min(NBuffers, MAX_CHECKPOINT_REQUESTS) instead of NBuffers in
CheckpointerShmemSize() to match the actual array size limit set in
CheckpointerShmemInit().  This prevents wasting shared memory when
NBuffers > MAX_CHECKPOINT_REQUESTS.  Also, fix the comment.

Reported-by: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/1439188.1754506714%40sss.pgh.pa.us
Author: Xuneng Zhou <[email protected]>
Co-authored-by: Alexander Korotkov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants